<?php
/**
 * Created by PhpStorm.
 * User: qishengqiang
 * Date: 2021-01-27
 * Time: 16:05
 */

namespace app\models;


use think\Model;

class ModelBase extends Model
{
    /**
     * @param null $parameters
     * 事例
     * $parameters = [
     *      'where' => [
     *          ['status','=','1']
     *      ],
     *      'join' => [
     *          [
     *              'centre',['centreName' => 1]
     *          ]
     *      ],
     *      'field' => '*',
     *      'order' => ['exhibitionId' => 'desc']
     *   ];
     * @param int $page
     * @param int $limit
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */


    public static function lists($parameters = null, $page = 1, $limit = 10)
    {
        $model = get_called_class();

        if (!is_array($parameters)) {
            $params[] = $parameters;
        } else {
            $params = $parameters;
        }

        $builder = new $model;
        if (isset($params['where'])) {
            $builder = $builder->where($params['where']);
        }

        if(isset($params['join'])){
            foreach($params['join'] as $value){
                $builder = $builder->haswhere($value[0], $value[1]);
            }
        }

        if (isset($params['order'])) {
            $builder = $builder->order($params['order']);
        }

        if (isset($params['field'])) {
            $builder = $builder->field($params['field']);
        }

        if (isset($params['group'])) {
            $builder = $builder->group($params['group']);
        }

        return $builder->paginate(['list_rows' => $limit, 'page' => $page, 'var_page' => 'page']);
    }

   
}